#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;

int myAtoi(string str)
{
    string tmp;
    for (int j = 0; j < str.size(); j++)
    {
        if (str[j] >= '0' && str[j] <= '9' || str[j] == '-')
            tmp += str[j];
        if (str[j] == '.' || (str[j] >= 'a' && str[j] <= 'z') || (str[j] >= 'A' && str[j] <= 'Z'))
            break;
        if (str[j] == '+' && (str[j + 1] < '0' || str[j + 1] > '9'))
            break;
        if (str[j] == '-' && (str[j + 1] < '0' || str[j + 1] > '9'))
            break;
        if ((str[j] >= '0' && str[j] <= '9') && (str[j + 1] < '0' || str[j + 1] > '9'))
            break;
    }

    int i = 0;
    int flag = 1;
    long long ret = 0;
    int next = 0;
    if (tmp[0] == '-')
    {
        flag = -1;
        next = 1;
        i = 1;
    }

    int num = tmp.find_first_of("123456789");
    if (tmp[0] == '-' && (tmp.size() - num) > 10)
        return INT_MIN;
    if ((tmp.size() - num) > 10)
        return INT_MAX;

    int j = tmp.size() - 1;
    while (j >= i)
    {
        ret += ((tmp[j] - '0') * pow(10, tmp.size() - j - 1));
        if ((ret * flag) <= INT_MIN)
            return INT_MIN;
        if (ret > INT_MAX)
            return INT_MAX;
        j--;
    }

    ret *= flag;
    return ret;
}

int main()
{
    int ret = myAtoi("    0000000000000   ");
    cout << ret << endl;
    return 0;
}